﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d80_cwbbMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d80_cwbb_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d80_cwbbMgr mgr = new d80_cwbbMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d80_cwbb(e.Parameters[d80_cwbb_Filter.ParamPrefix]));
            IList<d80_cwbb> list = mgr.FindAllByPage_d80_cwbb(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d80_cwbb_Filter.ParamPrefix]);
            d80_cwbb_MainStore.DataSource = list;
            d80_cwbb_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d80_cwbbMgr mgr = new d80_cwbbMgr();
            RowSelectionModel sm = d80_cwbb_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d80_cwbb _d80_cwbb = new d80_cwbb();
                _d80_cwbb.dzbm = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d80_cwbb(_d80_cwbb))
                {
                    log.Debug("d80_cwbb中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d80_cwbb_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d80_cwbbMgr mgr = new d80_cwbbMgr();
            d80_cwbb _d80_cwbb = new d80_cwbb();
            if (Hid.Text.Length > 0)
                _d80_cwbb = mgr.FindById_d80_cwbb(int.Parse(Hid.Text));
            
			_d80_cwbb.nf = Txtnf.Text.Trim();
			_d80_cwbb.gldm = Txtgldm.Text.Trim();
			_d80_cwbb.chhs = int.Parse(TxtNumchhs.Text.Trim());
			_d80_cwbb.chrs = int.Parse(TxtNumchrs.Text.Trim());
			_d80_cwbb.pchrs = int.Parse(TxtNumpchrs.Text.Trim());
			_d80_cwbb.wchrs = int.Parse(TxtNumwchrs.Text.Trim());
			_d80_cwbb.jfhj = Txtjfhj.Text.Trim();
			_d80_cwbb.grjf = Txtgrjf.Text.Trim();
			_d80_cwbb.ylbz = Txtylbz.Text.Trim();
			_d80_cwbb.qtbz = Txtqtbz.Text.Trim();
			_d80_cwbb.bczhs = int.Parse(TxtNumbczhs.Text.Trim());
			_d80_cwbb.bcahs = int.Parse(TxtNumbcahs.Text.Trim());
			_d80_cwbb.zyrs = int.Parse(TxtNumzyrs.Text.Trim());
			_d80_cwbb.wzyfy = Txtwzyfy.Text.Trim();
			_d80_cwbb.srs2 = int.Parse(TxtNumsrs2.Text.Trim());
			_d80_cwbb.ers2 = int.Parse(TxtNumers2.Text.Trim());
			_d80_cwbb.yrs2 = int.Parse(TxtNumyrs2.Text.Trim());
			_d80_cwbb.sfy2 = Txtsfy2.Text.Trim();
			_d80_cwbb.efy2 = Txtefy2.Text.Trim();
			_d80_cwbb.yfy2 = Txtyfy2.Text.Trim();
			_d80_cwbb.sbc2 = Txtsbc2.Text.Trim();
			_d80_cwbb.ebc2 = Txtebc2.Text.Trim();
			_d80_cwbb.ybc2 = Txtybc2.Text.Trim();
			_d80_cwbb.srs6 = int.Parse(TxtNumsrs6.Text.Trim());
			_d80_cwbb.ers6 = int.Parse(TxtNumers6.Text.Trim());
			_d80_cwbb.yrs6 = int.Parse(TxtNumyrs6.Text.Trim());
			_d80_cwbb.sfy6 = Txtsfy6.Text.Trim();
			_d80_cwbb.efy6 = Txtefy6.Text.Trim();
			_d80_cwbb.yfy6 = Txtyfy6.Text.Trim();
			_d80_cwbb.sbc6 = Txtsbc6.Text.Trim();
			_d80_cwbb.ebc6 = Txtebc6.Text.Trim();
			_d80_cwbb.ybc6 = Txtybc6.Text.Trim();
			_d80_cwbb.srs3 = int.Parse(TxtNumsrs3.Text.Trim());
			_d80_cwbb.ers3 = int.Parse(TxtNumers3.Text.Trim());
			_d80_cwbb.yrs3 = int.Parse(TxtNumyrs3.Text.Trim());
			_d80_cwbb.sfy3 = Txtsfy3.Text.Trim();
			_d80_cwbb.efy3 = Txtefy3.Text.Trim();
			_d80_cwbb.yfy3 = Txtyfy3.Text.Trim();
			_d80_cwbb.sbc3 = Txtsbc3.Text.Trim();
			_d80_cwbb.ebc3 = Txtebc3.Text.Trim();
			_d80_cwbb.ybc3 = Txtybc3.Text.Trim();
			_d80_cwbb.srs1 = int.Parse(TxtNumsrs1.Text.Trim());
			_d80_cwbb.ers1 = int.Parse(TxtNumers1.Text.Trim());
			_d80_cwbb.yrs1 = int.Parse(TxtNumyrs1.Text.Trim());
			_d80_cwbb.sbc1 = Txtsbc1.Text.Trim();
			_d80_cwbb.ebc1 = Txtebc1.Text.Trim();
			_d80_cwbb.ybc1 = Txtybc1.Text.Trim();
			_d80_cwbb.rs6 = int.Parse(TxtNumrs6.Text.Trim());
			_d80_cwbb.fy6 = Txtfy6.Text.Trim();
			_d80_cwbb.bc6 = Txtbc6.Text.Trim();
			_d80_cwbb.rs4 = int.Parse(TxtNumrs4.Text.Trim());
			_d80_cwbb.fy4 = Txtfy4.Text.Trim();
			_d80_cwbb.bc4 = Txtbc4.Text.Trim();
			_d80_cwbb.rs5 = int.Parse(TxtNumrs5.Text.Trim());
			_d80_cwbb.fy5 = Txtfy5.Text.Trim();
			_d80_cwbb.bc5 = Txtbc5.Text.Trim();
			_d80_cwbb.rs51 = int.Parse(TxtNumrs51.Text.Trim());
			_d80_cwbb.bc51 = Txtbc51.Text.Trim();
			_d80_cwbb.qtrs = int.Parse(TxtNumqtrs.Text.Trim());
			_d80_cwbb.qtbc = Txtqtbc.Text.Trim();
			_d80_cwbb.bzxx = Txtbzxx.Text.Trim();
			_d80_cwbb.mtsrs = int.Parse(TxtNummtsrs.Text.Trim());
			_d80_cwbb.mters = int.Parse(TxtNummters.Text.Trim());
			_d80_cwbb.mtyrs = int.Parse(TxtNummtyrs.Text.Trim());
			_d80_cwbb.mtsfy = Txtmtsfy.Text.Trim();
			_d80_cwbb.mtefy = Txtmtefy.Text.Trim();
			_d80_cwbb.mtyfy = Txtmtyfy.Text.Trim();
			_d80_cwbb.mtsbc = Txtmtsbc.Text.Trim();
			_d80_cwbb.mtebc = Txtmtebc.Text.Trim();
			_d80_cwbb.mtybc = Txtmtybc.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d80_cwbb(_d80_cwbb);
            else
                isok = mgr.Add_d80_cwbb(_d80_cwbb);
            if (isok)
            {
                d80_cwbb_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d80_cwbb中执行了保存（插入或修改），并成功");
                d80_cwbb_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}